aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog/[...slug].astro
blob: 5ba6b3bb18153c3d31da764a7189dcc9e46631e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
import { type CollectionEntry, getCollection, render } from "astro:content";
import blogPostSchema from "../../utils/schemas/blogPostSchema";
import breadcrumbSchema from "../../utils/schemas/breadcrumbSchema";
import Comments from "../../components/Comments.astro";
import dayjs from "dayjs";
import Layout from "../../layouts/BaseLayout.astro";
import personSchema from "../../utils/schemas/personSchema";
import websiteSchema from "../../utils/schemas/websiteSchema";
import { config } from "../../config";

type Props = CollectionEntry<"blog">;

export async function getStaticPaths() {
	const posts = await getCollection("blog", ({ data }) => {
		return data.draft !== true;
	});

	return posts.map((post) => ({
		params: { slug: post.id },
		props: post,
	}));
}

const post = Astro.props;

const { Content, remarkPluginFrontmatter } = await render(post);

const description = post.data.description;
const isBasedOn = post.data.basedOn;
const lang = post.data.lang;
const preview = `/images/preview/${post.id}.png`;
const slug = post.id;
const title = post.data.title;

const dateModified = post.data.dateModified?.toISOString();
const datePublished = post.data.datePublished.toISOString();
const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY");

const siteUrl = new URL("/", Astro.site).toString();

const schema = [
	websiteSchema({ siteUrl, name: config.og.website, description, lang }),
	personSchema({ siteUrl }),
	blogPostSchema({
		siteUrl,
		dateModified,
		datePublished,
		description,
		isBasedOn,
		lang,
		preview,
		slug,
		title,
	}),
	breadcrumbSchema({
		siteUrl,
		items: [
			{ name: "Home", url: "/" },
			{ name: "Blog", url: "/blog/" },
			{ name: title, url: `/blog/${slug}` },
		],
	}),
];
---

<style lang="scss">
	@use "../../scss/variables" as *;

	p {
		opacity: 0.5;
	}
</style>

<Layout title={title} description={description} preview={preview} lang={lang} schema={schema}>
	<article>
		<header>
			<h1>{title}</h1>

			<p>
				<small>
					Posted
					<time datetime={datePublished} lang="en">{formattedDate}</time>
					<span>&nbsp;•&nbsp;</span>
					<span>{remarkPluginFrontmatter.minutesRead}</span>
				</small>
			</p>
		</header>

		<section>
			<Content />
		</section>

		<section>
			<Comments />
		</section>
	</article>
</Layout>